minecraft_1122_moddingfandomcom-20200214-history
How to add eatable food
In this post, I'm going to quickly describe how I implemented (eatable food) in Minecraft. If you're new on this Wiki, please go and check out the "Things to know before using this Wiki"-Page so there won't be any questions or confusion. First of all, I am going to assume that you followed Loremaster's Videos and already have everything setup, basic structure done and an existing "ItemBase.java" class, or how ever you called it. With that class, you are able to implement new items into Minecraft. However, for this tutorial/post, we want to create food, that should also have a texture, a name and maybe most important, it should restore hunger. First of all, you're going to want to make a new class. I named mine "ItemBaseFood.java" and put it in my "items" package I basically copy and pasted the old class "ItemBase.java" into the "ItemBaseFood.java" class and got rid of the errors. As you can see, both classes are basically the same, but for "ItemBaseFood", the class gets extended by "ItemFood", not "Item". Also, we know have a constructor with 3 additional attributes. * int amount = A basic Integer that cointains the number of how much hungerpoints will be restored when eating this food (keep in mind, a player has 20 hunger. Each hungerpoint in the bar next to the health resembles actually 2 hungerpoints.) * float saturation = How long you are saturated after eating food. To inform yourself more about this, you can read more about the game mechanics of hunger here. If you don't want to do this, 0.3 - 0.6f seems to be a good default value. * boolean isWolfFood = This Boolean only determines if the food can be used to feed/heal a wolf. Whether you want your food to also be eaten by wolves or not is up to you. Except those 3 attributes, both classes work pretty much the same. So now you can actually already go into your "ModItems" class or however you called it and add the food you want to have ingame. I made myself an avocado. If you go into your game now, the item should already show up and you also should be able to eat it (while being in survival-mode and having a not full foodbar) But of course, we don't want to eat a violet-black Missing-Texture block, so go ahead and create your own texture for your food. Save your texture then as a .png and add it to the following path in your mod: src\main\resources\assets\yourModName\textures\items\yourFileName.png Go ahead and create a new .json file in the following directory src\main\resources\assets\yourModName\models\item\yourFileName.json !!!The file name from your texture and from the .json file should match to avoid confusion!!! Modify your .json to look like this: Change "sm" for your mod Name (As a reference to Loremaster "If your mod is named VoidMod, type vm here) Replace "avocado" with the name of your food/the name of the .json file/the name of the texture you made, but use only the name, not the ".png" at the end. Last but not least, go into your lang and edit the name of your food: That's it. If you've done everything right, you can go into the game now and eat your own food! If you have questions or need help, write a command or join Loremaster's Discord Server and message @Korlimann. :)Category:Tutorial